<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>点击</button>
    男:<input type="radio" name="sex" value="男" checked>
    <!-- name是分组的 -->
    女:<input type="radio" name="sex" value="女">


    <script>
        let btn = document.querySelector('button')
        let ipts = document.getElementsByName('sex')//根据属性选中元素 
        btn.onclick = function () {
            var res = ""
            for (let i = 0; i < ipts.length; i++) {
                let item = ipts[i]
                if (item.checked) {
                    res = item.value
                }
            }
            alert(res)
        }
    </script>
</body>

</html>